#!/usr/bin/env python
# encoding: utf-8

import requests

class MyRequest():

    def __init__(self) -> None:
        super().__init__()

    def requestBaiduHome(self):
        baiduUrl = "http://www.baidu.com"
        baiduResp = requests.get(baiduUrl)
        print(baiduResp.text)
        print("\n\n\n")

    def requestGitHubEvents(self):
        githubUrl="https://api.github.com/events"
        githubResp = requests.get(githubUrl)
        print(githubResp.text)

    def request12306LeftTicket(self):
        trainUrl = "https://kyfw.12306.cn/otn/leftTicket/query"
        requesParam = {
            "leftTicketDTO.train_date": "2018-06-10",
            "leftTicketDTO.from_station":"NCG",
            "leftTicketDTO.to_station":"FCG",
            "purpose_codes":"ADULT",
        }
        trainsResp = requests.get(trainUrl, params=requesParam)
        print(trainsResp.text)
        print("===============================================")
        respJson = trainsResp.json()
        retTest = respJson["data"]["result"]
        print(retTest)
        print("===============================================")
        for ret in  retTest:
            print(ret)
            print()
            split = str(ret).split("|")
            join = "\n".join(split)
            print(join)
            print()
            print("===============================================")
        print("===============================================")

    def req12306queryByTrainno(self):
        queryUrl = "https://kyfw.12306.cn/otn/czxx/queryByTrainNo"
        queryParam = {
            "train_no":"57000K10190N",
            "from_station_telecode":"NXG",
            "to_station_telecode": "FNG",
            "depart_date": "2018-06-10",
        }
        queryResp = requests.get(queryUrl, params=queryParam)
        print(queryResp.text)

    def reqLagouPosition(self):
        reqUrl = "https://www.lagou.com/jobs/positionAjax.json?needAddtionalResult=false"
        reqParam = {
            "first": "true",
            "pn": 1,
            "kd": "java",
        }
        urlParam = {
            "city": "上海",
            "needAddtionalResult": "false"
        }
        cookie = {
            "cookie":"_ga=GA1.2.720235910.1527748706; user_trace_token=20180531143826-39366a6f-649d-11e8-9329-5254005c3644; LGUID=20180531143826-3936714e-649d-11e8-9329-5254005c3644; index_location_city=%E5%85%A8%E5%9B%BD; WEBTJ-ID=20180608170617-163dea57c25541-0afe4c419bd1f6-3b60450b-921600-163dea57c263d9; _gid=GA1.2.66542573.1528448777; LGSID=20180608170617-33c29cfc-6afb-11e8-942d-5254005c3644; PRE_UTM=m_cf_cpt_baidu_pc; PRE_HOST=www.baidu.com; PRE_SITE=https%3A%2F%2Fwww.baidu.com%2Fs%3Fie%3Dutf-8%26f%3D8%26rsv_bp%3D1%26tn%3Dbaidu%26wd%3D%25E6%258B%2589%25E5%258B%25BE%25E7%25BD%2591%26oq%3Dbejson%26rsv_pq%3Def66d53100045a33%26rsv_t%3Dc255EA85SKRK7H5Idft80by1A0NZzZjbHvMaH3RT9cu5tYW%252B4K5b0if7e2o%26rqlang%3Dcn%26rsv_enter%3D1%26rsv_sug3%3D6%26rsv_sug1%3D7%26rsv_sug7%3D101%26bs%3Dbejson; PRE_LAND=https%3A%2F%2Fwww.lagou.com%2Flp%2Fhtml%2Fcommon.html%3Futm_source%3Dm_cf_cpt_baidu_pc; JSESSIONID=ABAAABAAAGGABCBA0466999D84093CC4F81032DC4800F77; Hm_lvt_4233e74dff0ae5bd0a3d81c6ccf756e6=1527750987,1527750995,1528448777,1528448803; _gat=1; X_HTTP_TOKEN=3cf3f014b21f22cec85db2b120d4d093; Hm_lpvt_4233e74dff0ae5bd0a3d81c6ccf756e6=1528449890; LGRID=20180608172449-caef1113-6afd-11e8-971c-525400f775ce; SEARCH_ID=d2323e87c31b4fc9ac5cc6981802bf14"
        }
        reqHeader = {
            # "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36",
            "User-Agent": "User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
                        "AppleWebKit/537.36 (KHTML, like Gecko)"
                        "Chrome/60.0.3112.90 Safari/537.36",
            "Accept": "application/json, text/javascript, */*; q=0.01",
            "Host": "www.lagou.com",
            "Origin": "https://www.lagou.com",
            "Referer": "https://www.lagou.com/jobs/list_Java?city=%E4%B8%8A%E6%B5%B7&cl=false&fromSearch=true&labelWords=&suginput="
        }
        resp = requests.post(reqUrl, reqParam, params=urlParam, cookies=cookie, headers=reqHeader)
        print(resp.text)



if __name__ == '__main__':
    my_request = MyRequest()
    # my_request.requestBaiduHome()
    # my_request.requestGitHubEvents()
    # my_request.request12306LeftTicket()
    # my_request.req12306queryByTrainno()
    my_request.reqLagouPosition()



